<style>
    .layui-table-cell {
        overflow: visible !important;
    }
    .layui-table-box {
        overflow: visible;
    }
    .layui-table-body {
        overflow: visible;
    }
    td .layui-form-select{
        margin-top: -10px;
        margin-left: -15px;
        margin-right: -15px;
    }
    #allBox table tbody tr td:nth-child(4) div,
    #allBox table tbody tr td:nth-child(6) div,
    #allBox table tbody tr td:nth-child(8) div,

    /*#timeBox table tbody tr td:nth-child(2) div,*/
    /*#timeBox table tbody tr td:nth-child(3) div,*/
    #timeBox table tbody tr td:nth-child(7) div,
    #timeBox table tbody tr td:nth-child(9) div,
    #timeBox table tbody tr td:nth-child(11) div{
        border: 1px solid #e5e5e5;
        margin: 0 1px;
        height: 36px;
        line-height: 36px;
    }
    #timeBox table tbody tr td:nth-child(2) div,
    #timeBox table tbody tr td:nth-child(3) div{
        margin: 0 1px;
        height: 36px;
        line-height: 36px;
        overflow: hidden !important;
    }
</style>
<div class="layui-fluid layui-anim febs-anim" id="febs-sale" lay-title="活动数据字典明细">
    <div class="layui-row febs-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body febs-table-full">
                    <form class="layui-form layui-table-form" lay-filter="sale-table-form">
                        <div class="layui-row">
                            <div class="layui-col-md10">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">油站地址</label>
                                        <div class="layui-input-inline">
                                            <input id="siteAddr" disabled type="text" name="name" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">品号</label>
                                        <div class="layui-input-inline">
                                            <input id="siteOilNumber" disabled type="text" name="name" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </form>
                    <div>
                        <!--全时-->
                        <div class="layui-inline" style="display: flex;align-items: center;">
                            <label style="font-size: 20px; font-weight: bold;" class="layui-form-label layui-form-label-sm">全时</label>
                            <div class="layui-input-inline">
                                <button id="btnAddAll" lay-event="saveAll" type="button" class="layui-btn layui-btn-xs"><i class="layui-icon">&#xe654;</i></button>
                            </div>
                        </div>
                        <div id="allBox">
                            <table id="saleTableAll" lay-filter="saleTable" lay-data="{id: 'saleTableAll'}"></table>
                        </div>
                        <!--分时间-->
                        <div id="timeBox">
                            <div class="layui-inline" style="display: flex;align-items: center;">
                                <label style="font-size: 20px; font-weight: bold;" class="layui-form-label layui-form-label-sm">分时</label>
                                <div class="layui-input-inline" style="display: flex; align-items: center;">
                                    <!--时间-->
                                    <!--<div class="layui-input-inline" style="margin-right: 5px;display: flex;align-items: center;">-->
                                        <!--<input type="text" name="date" id="beginDate" lay-verify="date" placeholder="开始时间选择" autocomplete="off" class="layui-input">- -->
                                        <!--<input type="text" name="dateEnd" id="endDate" lay-verify="dateEnd" placeholder="结束时间选择" autocomplete="off" class="layui-input">-->
                                    <!--</div>-->
                                    <form class="layui-form layui-table-form" lay-filter="sale-table-form">
                                        <!--星期-->
                                        <!--<div id="checkboxInput" class="layui-input-inline">-->
                                            <!--<input type="checkbox" name="week" lay-skin="primary" value="MON" title="周一">-->
                                            <!--<input type="checkbox" name="week" lay-skin="primary" value="TUE" title="周二">-->
                                            <!--<input type="checkbox" name="week" lay-skin="primary" value="WED" title="周三">-->
                                            <!--<input type="checkbox" name="week" lay-skin="primary" value="THU" title="周四">-->
                                            <!--<input type="checkbox" name="week" lay-skin="primary" value="FRI" title="周五">-->
                                            <!--<input type="checkbox" name="week" lay-skin="primary" value="SAT" title="周六">-->
                                            <!--<input type="checkbox" name="week" lay-skin="primary" value="SUN" title="周日">-->
                                        <!--</div>-->
                                    </form>
                                </div>
                                <div class="layui-input-inline">
                                    <button id="btnAddTime" lay-event="saveAll" type="button" class="layui-btn layui-btn-xs"><i class="layui-icon">&#xe654;</i></button>
                                </div>
                            </div>
                            <table id="saleTableTime" lay-filter="saleTableTime" lay-data="{id: 'saleTableTime'}"></table>
                        </div>
                        <!--接收油品-->
                        <p style="display: none;" id="oilTypeVal" th:text="${oilType}"></p>
                        <!--按钮-->
                        <div style="text-align: right; margin-top: 20px;"><button id="confim" lay-event="delete" type="button" class="layui-btn">ok</button></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="dictDetatl-option">
    <span shiro:hasPermission="shellActivityDetailDic:delete"><button lay-event="delete" type="button" class="layui-btn layui-btn-xs">删除</button></span>
    <span shiro:hasPermission="shellActivityDetailDic:delete"><button lay-event="save" type="button" class="layui-btn layui-btn-xs">保存</button></span>
</script>

<script data-th-inline="none" type="text/javascript">
    layui.use(['dropdown', 'jquery', 'laydate', 'form',  'table', 'febs', 'formSelects'], function () {
        var $ = layui.jquery,
            laydate = layui.laydate,
            febs = layui.febs,
            form = layui.form,
            table = layui.table,
            $view = $('#febs-sale'),
            formSelects = layui.formSelects,
            $query = $view.find('#query'),
            tableIns,
            tableInsTime,
            activityVal = localStorage.getItem('activityVal'),
            activityData = JSON.parse(activityVal),
            oilTypeVal = $('#oilTypeVal').text(),
            tableAllData=[],
            tableTimeData = [],
            oilCode='',
            activityOilId = '',
            isSave = true;
        var consumerData = [],
            unitData = [],
            saleData = [],
            activityZyData = [],
            activityJzData = [],
            weekData = [
                {
                    name: '周一',
                    value: 'MON'
                },
                {
                    name: '周二',
                    value: 'TUE'
                },
                {
                    name: '周三',
                    value: 'WED'
                },
                {
                    name: '周四',
                    value: 'THU'
                },
                {
                    name: '周五',
                    value: 'FRI'
                },
                {
                    name: '周六',
                    value: 'SAT'
                },
                {
                    name: '周日',
                    value: 'SUN'
                }
            ];

        //select请求
        consumerSelect();
        unitSelect();
        saleSelect();
        activityJzSelect();
        activityZySelect();
        activityData.shellActivityOilDetailList=null;
        setTimeout(function () {
            returnData()
        },500);
        //分时-时间
        laydate.render({
            elem: '#beginDate',
            type: 'datetime',
            format: 'yyyy-MM-dd HH:mm:ss',
            trigger: 'click'
        });
        laydate.render({
            elem: '#endDate',
            type: 'datetime',
            format: 'yyyy-MM-dd HH:mm:ss',
            trigger: 'click'
        });
        function renderSelectOptions(data, settings) {
            settings =  settings || {};
            var valueField = settings.valueField || 'value',
                textField = settings.textField || 'text',
                selectedValue = settings.selectedValue || "";
            var html = [];
            for(var i=0, item; i < data.length; i++){
                item = data[i];
                html.push('<option value="');
                html.push(item[valueField]);
                html.push('"');
                if(selectedValue && item[valueField] == selectedValue ){
                    html.push(' selected="selected"');
                }
                html.push('>');
                html.push(item[textField]);
                html.push('</option>');
            }
            return html.join('');
        }
        initTable();
        initTableTime();
        form.render();
        //地址-赋值
        $('#siteAddr').val(activityData.address);
        //油品-赋值
        oilTypeFormat();
        //全时-添加
        $('#btnAddAll').on('click', function () {
            if (!isSave) {
                febs.alert.warn('请先保存');
                return false
            }
            var tableAll = layui.table.cache.saleTableAll;
            tableAll.push({
                tempId: new Date().valueOf(),
                consumerType: '',
                type: activityData.type,
                activityUnit: '',
                activityBase: '',
                saleType: '',
                salePrice: '',
                activityCode: '',
                activityValue: '',
                oilCode: oilCode,
                activityOilId: activityData.id
            });
            tableIns.reload({data: tableAll, page: false});
            form.render();
            isSave = false
        });
        //分时-添加
        $('#btnAddTime').on('click', function () {
            if (!isSave) {
                febs.alert.warn('请先保存');
                return false
            }
            var tableTime = layui.table.cache.saleTableTime;
            var tableIndex = tableTime.length;
            tableTime.push({
                index: tableIndex,
                tempId: new Date().valueOf(),
                beginTime: '',
                endTime: '',
                weeks: '',
                consumerType: '',
                type: activityData.type,
                activityUnit: '',
                activityBase: '',
                saleType: '',
                salePrice: '',
                activityCode: '',
                activityValue: '',
                oilCode: oilCode
            });
            tableInsTime.reload({data: tableTime, page: false});
            form.render();
            isSave = false
        });
        //列表-时间选择-初始化
        function timeSelectInit(id, index) {
            setTimeout(function () {
                laydate.render({
                    elem: id,
                    type: 'datetime',
                    format: 'yyyy-MM-dd HH:mm:ss',
                    trigger: 'click'
                });
                var weekName = 'week-select'+index
                formSelects.value(weekName);
            }, 500);
        }
        function weeksMultiSelect (d) {
            var _weekName = 'week-select'+ d.index,
                html='';
                dweek = d.weeks.split(',');
            for (var i=0;i<weekData.length;i++) {
                if (weekData[i].value==dweek[i]){
                    html += '<option name="weekOption" selected value="'+weekData[i].value+'">'+weekData[i].name+'</option>'
                } else {
                    html += '<option name="weekOption" value="'+weekData[i].value+'">'+weekData[i].name+'</option>'
                }
            }


            var _html = '<select name="weeks" lay-verify="required" xm-select-direction="down" xm-select-skin="default" xm-select="'+_weekName+'">' +
                html+
                '</select>';
            return _html
        }
        //列表-按钮-全时
        table.on('tool(saleTable)', function (obj) {

            var data = obj.data,
                layEvent = obj.event,
                tr = obj.tr;
            if (layEvent == 'delete') {
                var oldData = layui.table.cache.saleTableAll;
                for(var i=0, row; i < oldData.length; i++){
                    row = oldData[i];
                    if (data.id) {
                        if(oldData[i].id == data.id){
                            oldData.splice(i, 1);    //删除一项
                        }
                        continue;
                    } else {
                        if(oldData[i].tempId == data.tempId){
                            oldData.splice(i, 1);    //删除一项1
                        }
                        continue;
                    }
                }
                //删除local里
                var _activityVal = localStorage.getItem('activityVal'),
                    oldDetail = null,
                    oldShellDetail = localStorage.getItem('ShellActivityOilDetail');

                _activityVal = JSON.parse(_activityVal);
                if (_activityVal.shellActivityOilDetailList.length > 0) {
                    oldDetail = _activityVal.shellActivityOilDetailList;
                    for(var j = 0; j < oldDetail.length; j++) {
                        if (oldDetail[j].id) {
                            if(oldDetail[j].id == data.id){
                                oldDetail.splice(0, 1);    //删除一项
                            }
                            continue;
                        }  else {
                            if (oldDetail[j].tempId == data.tempId) {
                                oldDetail.splice(j, 1)
                            }
                        }
                    }
                    activityData = _activityVal; //重新负值
                    localStorage.setItem('activityVal', JSON.stringify(_activityVal))
                }
                if (oldShellDetail) {
                    oldShellDetail = JSON.parse(oldShellDetail);
                    for(var k = 0; k < oldShellDetail.length; k++) {
                        if (oldShellDetail[k].id) {
                            if(oldShellDetail[k].id == data.id){
                                oldShellDetail.splice(0, 1);    //删除一项
                            }
                            continue;
                        }  else {
                            if (oldShellDetail[k].tempId == data.tempId) {
                                oldShellDetail.splice(k, 1)
                            }
                        }
                    }
                    localStorage.setItem('ShellActivityOilDetail', JSON.stringify(oldShellDetail))
                }
                tableIns.reload({
                    data : oldData
                });
                isSave = true;
            }
            if (layEvent == 'editValue') {
                layui.$(this).on('input porpertychange',function(e){
                    var val= layui.$(this).val();
                    var name= layui.$(this).attr('name');
                    data[name]=val;
                    obj.update(data);//更新行对象数据
                })
            }
            if (layEvent == 'consumer') {
                var select = tr.find("select[name='consumerType']");
                if(select){
                    var selectedVal = select.val();
                    $.extend(obj.data, {'consumerType': selectedVal});
                    updateRow(obj)	//更新行记录对象
                }
            }
            if (layEvent== 'save') {
                var _rowObj = {
                    consumerType: tr.find("select[name='consumerType']").val(),
                    activityUnit: tr.find("select[name = 'activityUnit']").val(),
                    activityBase: data.activityBase,
                    saleType: tr.find("select[name='saleType']").val(),
                    salePrice: data.salePrice,
                    activityCode: tr.find("select[name='activityCode']").val(),
                    activityValue: tr.find("td[data-field='activityValue'] > div").text()
                };
                $.extend(obj.data, _rowObj);
                updateRow(obj);
                isSave = true
                febs.alert.success('保存成功')
            }
        });
        //列表-按钮-分时
        table.on('tool(saleTableTime)', function (obj) {
            var data = obj.data,
                layEvent = obj.event,
                tr = obj.tr;
            if (layEvent == 'delete') {
                var oldData = layui.table.cache.saleTableTime;
                for(var i=0, row; i < oldData.length; i++){
                    row = oldData[i];
                    if(oldData[i].tempId == data.tempId){
                        oldData.splice(i, 1);    //删除一项
                    }
                    continue;
                }
                tableInsTime.reload({
                    data : oldData
                });
                isSave = true
            }
            if (layEvent == 'editValue') {
                layui.$(this).on('input porpertychange',function(e){
                    var val= layui.$(this).val();
                    var name= layui.$(this).attr('name');
                    data[name]=val;
                    obj.update(data);//更新行对象数据
                })
            }
            if (layEvent == 'consumer') {
                var select = tr.find("select[name='consumerType']");
                if(select){
                    var selectedVal = select.val();
                    $.extend(obj.data, {'consumerType': selectedVal});
                    updateRowTime(obj)	//更新行记录对象
                }
            }
            if (layEvent== 'save') {
                var week_box = [],
                    weekString = '';
                tr.find($("font[fsw='xm-select']")).each(function () {
                    var _item = $(this).html();
                    for (var i=0;i<weekData.length;i++) {
                        if (_item==weekData[i].name){
                            week_box.push(weekData[i].value)
                        }
                    }
                });
                weekString = week_box.toString();
                var _rowObj = {
                    consumerType: tr.find("select[name='consumerType']").val(),
                    activityUnit: tr.find("select[name = 'activityUnit']").val(),
                    activityBase: data.activityBase,
                    beginTime: tr.find("input[name='dateBegin']").val(),
                    endTime: tr.find("input[name='dateEnd']").val(),
                    weeks: weekString,
                    saleType: tr.find("select[name='saleType']").val(),
                    salePrice: data.salePrice,
                    activityCode: tr.find("select[name='activityCode']").val(),
                    activityValue: tr.find("td[data-field='activityValue'] > div").text()
                };
                $.extend(obj.data, _rowObj);
                updateRowTime(obj);
                isSave = true;
                febs.alert.success('保存成功')
            }
        });
        //ok
        $('#confim').on('click', function () {
            var _allData = layui.table.cache.saleTableAll,
               _timeData = layui.table.cache.saleTableTime,
                beginDate = '',
                endDate = '',
                week_box = [],
                weekString = '',
                oldDetail = localStorage.getItem('ShellActivityOilDetail'),
                currentData = [];
            //获取local里存的数据
            if (oldDetail) {
                oldDetail = JSON.parse(oldDetail);
                currentData = oldDetail;
            } else {
                if (activityData.shellActivityOilDetailList) {
                    currentData = activityData.shellActivityOilDetailList
                }
            }
            $('input[type=checkbox]:checked').each(function() {
                week_box.push($(this).val());
            });
            weekString = week_box.toString();
            //取第一个table
            $.each(_allData, function (index,item) {
                item.activityOilId= activityOilId;
                item.shellId = activityData.shellId;
                item.activityId = activityData.shellActivityOilList[0].activityId;
                currentData.push(item)
            });
            //取第二个table
            $.each(_timeData, function (i,t) {
                t.activityOilId= activityOilId;
                t.shellId = activityData.shellId;
                t.activityId = activityData.shellActivityOilList[0].activityId;

                currentData.push(t)
            });
            //取已经保存的数据-分开去重
            var _currentIdData = [], _currentTidData = [];
            $.each(currentData, function (index, item) {
               if (item.id) {
                   _currentIdData.push(item)
               }  else {
                   _currentTidData.push(item)
               }
            });
            _currentIdData = heavyArrayId(_currentIdData);
            _currentTidData = heavyArray(_currentTidData);
            // 合并去重后的两个数组
            $.each(_currentIdData,function (index,item) {
               _currentTidData.push(item)
            });
            var _currentData =JSON.stringify(_currentTidData);
            localStorage.setItem('ShellActivityOilDetail', _currentData);
            layer.closeAll();
            parent.tools.reloadTable()
        });
        //特殊活动值-赋值
        form.on('select(activity-code-filter)', function(data){
            var _inputText = '';
            if (activityData.type == 0) {
                $.each(activityZyData,function (index,item) {
                    if (item.value == data.value) {
                        _inputText = item.inputValue;
                        return
                    }
                });
            } else {
                $.each(activityZyData,function (index,item) {
                    if (item.value == data.value) {
                        _inputText = item.inputValue;
                        return
                    }
                });
            }

            $(this).closest("tr").find("td[data-field='activityValue'] div").html("");
            $(this).closest("tr").find("td[data-field='activityValue'] div").html(_inputText);
            form.render();
        });
        form.on('select(activityTime-code-filter)', function(data){
            var _inputText = '';
            $.each(activityZyData,function (index,item) {
                if (item.value == data.value) {
                    _inputText = item.inputValue
                    return
                }
            });
            $(this).closest("tr").find("td[data-field='activityValue'] div").html("");
            $(this).closest("tr").find("td[data-field='activityValue'] div").html(_inputText);
            form.render();
        });
        //更新行数据
        function updateRow (obj) {
            var oldData = layui.table.cache.saleTableAll;
            for(var i=0, row; i < oldData.length; i++){
                row = oldData[i];
                if(row.tempId == obj.data.tempId){
                    $.extend(oldData[i], obj.data);
                    return;
                }
            }
            tableIns.reload({
                data : oldData
            });
        }
        //更新行数据-分时
        function updateRowTime (obj) {
            var oldData = layui.table.cache.saleTableTime;
            for(var i=0, row; i < oldData.length; i++){
                row = oldData[i];
                if(row.tempId == obj.data.tempId){
                    $.extend(oldData[i], obj.data);
                    return;
                }
            }
            tableInsTime.reload({
                data : oldData
            });
        }
        //列表数据-请求
        function initTable() {
            tableIns = febs.table.init({
                elem: '#saleTableAll',
                // url: ctx + 'shellActivity/dictDetailList',
                cols: [[
                    {type: 'checkbox'},
                    {field: 'consumerType', title: '顾客群体', minWidth: 100, templet: function(d){
                            var options = renderSelectOptions(consumerData, {valueField: "value", textField: "name", selectedValue: d.consumerType});
                            return '<a lay-event="type"></a><select name="consumerType" lay-filter="consumerType"><option value="">请选择分类</option>' + options + '</select>';
                        }},
                    {field: 'activityUnit', title: '促销门槛单位', minWidth: 100, templet: function(d){
                            var options = renderSelectOptions(unitData, {valueField: "value", textField: "name", selectedValue: d.activityUnit});
                            return '<a lay-event="type"></a><select name="activityUnit" lay-filter="activityUnit"><option value="">请选择分类</option>' + options + '</select>';
                        }},
                    {field: 'activityBase', title: '促销门槛', minWidth: 100, edit: 'text'},
                    {field: 'saleType', title: '折扣类型', minWidth: 100, templet: function(d){
                            var options = renderSelectOptions(saleData, {valueField: "value", textField: "name", selectedValue: d.saleType});
                            return '<a lay-event="type"></a><select name="saleType" lay-filter="saleType"><option value="">请选择分类</option>' + options + '</select>';
                        }},
                    {field: 'salePrice', title: '折扣', minWidth: 100, edit: 'text'},
                    {field: 'activityCode', title: '特殊活动编码', minWidth: 100, templet: function(d){
                            if (activityData.type == 0) {
                                var options = renderSelectOptions(activityZyData, {valueField: "value", textField: "name", selectedValue: d.activityCode});
                                return '<a lay-event="type"></a><select name="activityCode" lay-filter="activity-code-filter"><option value="">请选择分类</option>' + options + '</select>';
                            } else {
                                var options = renderSelectOptions(activityJzData, {valueField: "value", textField: "name", selectedValue: d.activityCode});
                                return '<a lay-event="type"></a><select name="activityCode" lay-filter="activityTime-code-filter"><option value="">请选择分类</option>' + options + '</select>';
                            }

                        }},
                    {field: 'activityValue', title: '特殊活动值', minWidth: 100, edit: 'text'},
                    {title: '操作', toolbar: '#dictDetatl-option', minWidth: 100}
                ]],
                data: tableAllData,
                page: false,
                done: function (res, curr, count) {
                    layer.close(layer.load(2));
                },
            });
        }
        //分时-列表数据请求
        function initTableTime() {
            tableInsTime = febs.table.init({
                elem: '#saleTableTime',
                // url: ctx + 'shellActivity/dictDetailList',
                cols: [[
                    {type: 'checkbox'},
                    {field: 'beginTime', title: '开始时间', minWidth: 100, templet: function (d) {
                            var _id = "beginDate" + d.index;
                            var _html = '<input type="text" id="'+_id+'" value="'+d.beginTime+'" name="dateBegin" lay-verify="date" placeholder="开始时间" autocomplete="off" class="layui-input">';
                            var _beginId = '#'+_id;
                            timeSelectInit(_beginId, d.index);
                            return _html
                        }},
                    {field: 'endTime', title: '结束时间', minWidth: 100, templet: function (d) {
                            var _id = "endDate" + d.index;
                            var _html = '<input type="text" id="'+_id+'" value="'+d.endTime+'"  name="dateEnd" lay-verify="dateEnd" placeholder="结束时间" autocomplete="off" class="layui-input">';
                            var _endId = '#'+_id;
                            timeSelectInit(_endId, d.index);
                            return _html
                        }},
                    {field: 'weeks', title: '星期', minWidth: 150, templet: function (d) {
                            var select = weeksMultiSelect(d);
                        return select
                        }},
                    {field: 'consumerType', title: '顾客群体', minWidth: 100, templet: function(d){
                            var options = renderSelectOptions(consumerData, {valueField: "value", textField: "name", selectedValue: d.consumerType});
                            return '<a lay-event="type"></a><select name="consumerType" lay-filter="consumerType"><option value="">请选择分类</option>' + options + '</select>';
                        }},
                    {field: 'activityUnit', title: '促销门槛单位', minWidth: 100, templet: function(d){
                            var options = renderSelectOptions(unitData, {valueField: "value", textField: "name", selectedValue: d.activityUnit});
                            return '<a lay-event="type"></a><select name="activityUnit" lay-filter="activityUnit"><option value="">请选择分类</option>' + options + '</select>';
                        }},
                    {field: 'activityBase', title: '促销门槛', minWidth: 100, edit: 'text'},
                    {field: 'saleType', title: '折扣类型', minWidth: 100, templet: function(d){
                            var options = renderSelectOptions(saleData, {valueField: "value", textField: "name", selectedValue: d.saleType});
                            return '<a lay-event="type"></a><select name="saleType" lay-filter="saleType"><option value="">请选择分类</option>' + options + '</select>';
                        }},
                    {field: 'salePrice', title: '折扣', minWidth: 100, edit: 'text'},
                    {field: 'activityCode', title: '特殊活动编码', minWidth: 100, templet: function(d){
                            if (activityData.type == 0) {
                                var options = renderSelectOptions(activityZyData, {valueField: "value", textField: "name", selectedValue: d.activityCode});
                                return '<a lay-event="type"></a><select name="activityCode" lay-filter="activityTime-code-filter"><option value="">请选择分类</option>' + options + '</select>';
                            } else {
                                var options = renderSelectOptions(activityJzData, {valueField: "value", textField: "name", selectedValue: d.activityCode});
                                return '<a lay-event="type"></a><select name="activityCode" lay-filter="activityTime-code-filter"><option value="">请选择分类</option>' + options + '</select>';
                            }

                        }},
                    {field: 'activityValue', title: '特殊活动值', minWidth: 100, edit: 'text'},
                    {title: '操作', toolbar: '#dictDetatl-option', minWidth: 100}
                ]],
                data: tableTimeData,
                page: false,
                done: function (res, curr, count) {
                    layer.close(layer.load(2));
                }
            });
        }
        //星期-多选
        formSelects.config('oilPrice-ad-site', {
            searchUrl: '',
            response: {
                statusCode: 200
            },
            beforeSuccess: function (id, url, searchVal, result) {

                return result;
            },
            error: function (id, url, searchVal, err) {
                console.error(err);
                febs.alert.error('获取油站列表失败');
            }
        });
        //油品-判断
        function oilTypeFormat() {
            if (oilTypeVal == 0) {
                $('#siteOilNumber').val('0#柴油');
                oilCode = '#0';
                activityOilId = activityData.shellActivityOilList[0].id;
                return false;
            } else if (oilTypeVal == 92) {
                $('#siteOilNumber').val('92#汽油');
                oilCode = '#92';
                activityOilId = activityData.shellActivityOilList[1].id;
                return false;
            } else if (oilTypeVal == 95) {
                $('#siteOilNumber').val('95#汽油');
                activityOilId = activityData.shellActivityOilList[2].id;
                oilCode = '#95';
                return false;
            } else {
                $('#siteOilNumber').val('98#汽油');
                oilCode = '#98';
                activityOilId = activityData.shellActivityOilList[3].id;
                return false;
            }
        }
        // 客户select
        function consumerSelect() {
            febs.get(ctx + 'shellActivity/activityDicDetailList', {'code': 'CUSTOMER'}, function (res) {
                if (res.code === 200) {
                    var _data = [];
                    res.data.map(function (item,index) {
                        // $('#siteSelect').append(new Option(item.siteName, item.siteid));// 下拉菜单里添加元素
                        _data.push({
                            value: item.code,
                            name: item.code
                        })
                    });
                    consumerData = _data;
                }
            })
        }
        // 促销select
        function unitSelect() {
            febs.get(ctx + 'shellActivity/activityDicDetailList', {'code': 'SALEUNIT'}, function (res) {
                if (res.code === 200) {
                    var _data = [];
                    res.data.map(function (item,index) {
                        // $('#siteSelect').append(new Option(item.siteName, item.siteid));// 下拉菜单里添加元素
                        _data.push({
                            value: item.code,
                            name: item.code
                        })
                    });
                    unitData = _data;
                }
            })
        }
        // 折扣select
        function saleSelect() {
            febs.get(ctx + 'shellActivity/activityDicDetailList', {'code': 'SALETYPE'}, function (res) {
                if (res.code === 200) {
                    var _data = [];
                    res.data.map(function (item,index) {
                        // $('#siteSelect').append(new Option(item.siteName, item.siteid));// 下拉菜单里添加元素
                        _data.push({
                            value: item.code,
                            name: item.code
                        })
                    });
                    saleData = _data;
                }
            })
        }
        // 特殊-自营
        function activityZySelect() {
            febs.get(ctx + 'shellActivity/shellActivityDicList', {'type': '0'}, function (res) {
                if (res.code === 200) {
                    var _data = [];
                    res.data.map(function (item,index) {
                        // $('#siteSelect').append(new Option(item.siteName, item.siteid));// 下拉菜单里添加元素
                        _data.push({
                            value: item.activityCode,
                            name: item.activityName,
                            inputValue: item.activityValue
                        })
                    });
                    activityZyData = _data;
                }
            })
        }
        // 特殊-竞争
        function activityJzSelect() {
            febs.get(ctx + 'shellActivity/shellActivityDicList', {'type': '1'}, function (res) {
                if (res.code === 200) {
                    var _data = [];
                    res.data.map(function (item,index) {
                        // $('#siteSelect').append(new Option(item.siteName, item.siteid));// 下拉菜单里添加元素
                        _data.push({
                            value: item.activityCode,
                            name: item.activityName,
                            inputValue: item.activityValue
                        })
                    });
                    activityJzData = _data;
                }
            })
        }
        // 数据回填
        function returnData( ) {
            var localTable = localStorage.getItem('ShellActivityOilDetail');
            var currentAllArr=[],currentTimeArr=[];
            $.each(activityData.shellActivityOilDetailList, function (index,item) {
                if (item.oilCode == oilCode) {
                    if (item.weeks){
                        form.render();
                        currentTimeArr.push(item)
                    } else {
                        currentAllArr.push(item)
                    }
                }
            });
            if (localTable) {
                var _localTable =JSON.parse(localTable);
                localTable = heavyArray(_localTable);
                $.each(localTable, function (index,item) {
                    if (item.oilCode == oilCode) {
                        if (item.weeks) {
                            form.render();
                            currentTimeArr.push(item);
                        } else {
                            currentAllArr.push(item)
                        }
                        currentAllArr = heavyArrayId(currentAllArr);
                        currentTimeArr = heavyArrayId(currentTimeArr);
                        tableIns.reload({data: currentAllArr, page: false});
                        tableInsTime.reload({data: currentTimeArr, page: false});
                    } else {
                        tableIns.reload({data: currentAllArr, page: false});
                        tableInsTime.reload({data: currentTimeArr, page: false});
                    }
                })

            } else {
                tableIns.reload({data: currentAllArr, page: false});
                tableInsTime.reload({data: currentTimeArr, page: false});
            }
        }
        // 数组去重-tempId
        function heavyArray(data) {
            var result = [], obj = {};
            for (var i = 0; i < data.length; i++) {
                if (!obj[data[i].tempId]) {
                    result.push(data[i]);
                    obj[data[i].tempId] = true;
                }
            }
            return result;
        }
        // 数组去重-id
        function heavyArrayId(data) {
            var result = [], obj = {};
            for (var i = 0; i < data.length; i++) {
                if(!obj[data[i].id]) {
                    result.push(data[i]);
                    obj[data[i].id] = true;
                }
            }
            return result;
        }
    })
</script>